﻿using StaffingSystem.EF;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace StaffingSystem.Controllers
{
    public class InviteworkController : Controller
    {
        Management db;
        // GET: Invitework
        public ActionResult Invite()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Invite(Viewone ta)
        {
            JsonResult result = new JsonResult();
            db = new Management();
            //使用拼接字符串的方式，将要执行的存储过程名称以及参数拼接在一起
            StringBuilder procString = new StringBuilder();
            procString.Append("PerInterview_insert");
            procString.Append(" @Names,");
            procString.Append("@Sexs,");
            procString.Append("@Ages,");
            procString.Append("@Nations,");
            procString.Append("@Educations,");
            procString.Append("@IDNumbers,");
            procString.Append("@Phones,");
            procString.Append("@Addresss,");
            procString.Append("@pays");
            
            SqlParameter[] sq= {
                    new SqlParameter("@Names",ta.Name),
                    new SqlParameter("@Sexs",ta.Sex),
                    new SqlParameter("@Ages",ta.Age),
                    new SqlParameter("@Nations",ta.Nation),
                    new SqlParameter("@Educations",ta.Education),
                    new SqlParameter("@IDNumbers",ta.IDNumber),
                    new SqlParameter("@Phones",ta.Phone),
                    new SqlParameter("@Addresss",ta.Address),
                    new SqlParameter("@pays",ta.Pay)
              };
            int a = db.Database.ExecuteSqlCommand(procString.ToString(),sq);
            if (a > 0)
            {
                result.Data = new
                {
                    State = "1",
                    Message = "添加成功"
                };
            }
            else
            {
                result.Data = new
                {
                    State = "2",
                    Message = "添加失败"
                };
            }
            return result;

        }
    }
}